package com.boc.langxiang.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;

import com.boc.langxiang.R;
import com.boc.langxiang.util.SPUtil;
import com.squareup.picasso.Picasso;

import butterknife.BindView;
import butterknife.ButterKnife;

public class WelcomeActivity extends BaseActivity implements Handler.Callback {

    @BindView(R.id.imageview)
    ImageView mImageview;

    private Handler mHandler;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_welcome);
        ButterKnife.bind(this);
        Picasso.with(mContext)
                .load(R.drawable.bg_welcome)
                .into(mImageview);
        mHandler = new Handler(this);
        mHandler.sendEmptyMessageDelayed(100, 2000);
    }

    @Override
    public boolean handleMessage(Message msg) {
        boolean firstUse = (boolean) SPUtil.get(mContext, "firstUse", true);
        Intent intent;
        if (firstUse) {
            intent = new Intent(mContext, MainActivity.class);
        } else {
            intent = new Intent(mContext, MainActivity.class);
        }
        SPUtil.put(mContext, "firstUse", false);
        startActivity(intent);
        finish();
        return true;
    }
}
